<template>
  <div class='app'>
      <!--audio src="http://8.136.193.200:8888/rootImg/audio/jxja/202107386.mp3" autoplay ></audio-->
      <el-table
        v-loading="loading"
        :data="tableData"
        
        :show-summary="showSummary"
        
        :summary-method="getSummaries"
        height="100%"
        border
        stripe
        ref="table"
        highlight-current-row
        @current-change="handleCurrentChange"
        @selection-change="handleSelectionChange"
        @sort-change="sortChange"
        @row-click="rowClick"
        @row-dblclick="rowDbClick"
        :header-cell-class-name="handleHeaderClass"
        @header-click="handleHeaderCLick"
        style="width: 100%" v-if="showTable&&isTree==''&&isMobile=='N'">
         <el-table-column
          type="selection"
          width="30">
        </el-table-column>
        <el-table-column
          :prop="item.field"
          :label="item.names"
          :sortable="item.sort ? 'custom':false"
          :fixed="item.fixed"
          :width="item.width" v-for="(item,index) in listFieldNew " :key='index'>
          <template slot-scope="scope">
            <el-tooltip placement="top" v-if="item.type=='image'" >
                <div slot="content"><div style="background:#fff">
                  <el-image 
                    style="width: 220px"
                    :src="scope.row[item.field].split(',')[0]" 
                    :preview-src-list="scope.row[item.field].split(',')">
                </el-image>
                  </div></div>
                <img :src="scope.row[item.field].split(',')[0]"  style='height:40px;margin-left:auto;margin-right:auto'/>
            </el-tooltip>
            
            <span  v-else-if="item.type=='link'">
              <el-link type="primary" @click="openWins(item.exkey,scope.row)" ><div v-html="scope.row[item.field]" :style="{'color':scope.row.colors,'maxHeight':'150px','overflow':'auto','textAlign':item.isCenter=='Y' ? 'center':'left'}"></div></el-link>
              </span>

            <el-tooltip  placement="top" v-else-if="item.isTip=='Y'" >
              <div slot="content" ><span style="font-size:18px">{{scope.row[item.field]}}</span></div>
              <div class="impleName" :style="{'color':scope.row.colors}" v-html="scope.row[item.field]"></div>
            </el-tooltip>
            <div v-html="scope.row[item.field]"  v-else-if="item.isShowAll=='Y'"  :style="{'color':scope.row.colors,'maxHeight':'150px','overflow':'auto','textAlign':item.isCenter=='Y' ? 'center':'left'}"></div>
            <div v-html="scope.row[item.field]"  v-else-if="item.type=='tel'" @click="callPhone(scope.row[item.field])" :style="{'color':scope.row.colors,'maxHeight':'150px','overflow':'auto','textAlign':item.isCenter=='Y' ? 'center':'left'}"></div>
          
            <div v-html="scope.row[item.field]" class="impleName" v-else  :style="{'color':scope.row.colors,'textAlign':item.isCenter=='Y' ? 'center':'left'}"></div>
          </template>
        </el-table-column>

        <el-table-column
          fixed="right"
          :prop="btnField.field"
          :label="btnField.names"
          :width="btnWidth" v-if="btnField" >
           <template slot-scope="scope">
             <div style='display:inline' v-for="(item,index) in scope.row[btnField.field]" :key="index">
                  <el-button  type="success" :style="{'background':item.colors,'marginLeft':'5px','borderColor':item.colors}" size="mini" @click="btnClick(item)" v-if="(!item.show||scope.row[item.show]=='Y')&&item.isChild!='Y'" >{{item.buttonName}}</el-button>
                  <el-dropdown v-if="item.isChild=='Y'" style="margin-left:5px"  @command="handleCommand">
                    <el-button type="primary" size="mini">
                      更多<i class="el-icon-arrow-down el-icon--right"></i>
                    </el-button>
                    <el-dropdown-menu slot="dropdown" >
                      <el-dropdown-item v-for="(child,index2) in item.child" :key="index2" :command="child.command" >{{child.buttonName}}</el-dropdown-item>
                     
                    </el-dropdown-menu>
                </el-dropdown>
                </div>
            
            
          </template>
        </el-table-column>
        <div slot="empty">
          
             <img src="../../assets/img/nodata.png" style='width:50%'/>
          
           <div>
            暂无数据
           </div>
        </div>
      </el-table>


      <el-table
        v-loading="loading"
        :data="tableData"
        height="100%"
        border
        stripe
        ref="table"
        highlight-current-row
        @current-change="handleCurrentChange"
        @selection-change="handleSelectionChange"
        @sort-change="sortChange"
        @row-click="rowClick"
        @row-dblclick="rowDbClick"
        :header-cell-class-name="handleHeaderClass"
        @header-click="handleHeaderCLick"
        
        :show-summary="showSummary"
        
        :summary-method="getSummaries"
        style="width: 100%" v-if="showTable&&isTree=='Y'&&isMobile=='N'"
      
        :row-key="treeId"
        lazy
        :load="load"
        @expand-change="expandChange"
        :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
      
        >
        <el-table-column
          type="selection"
          width="30">
        </el-table-column>
        <el-table-column
          :prop="item.field"
          :label="item.names"
          :sortable="item.sort ? 'custom':false"
          :width="item.width" v-for="(item,index) in listFieldNew " :key='index'>
         
        </el-table-column>

       <div slot="empty">
          <p>
             <img src="../../assets/img/nodata.png"/>
          </p>
          <p>
            暂无数据
          </p>
        </div>
      </el-table>

      <el-table
        v-loading="loading"
        :data="tableData"
        height="100%"
        border
        stripe
        ref="table"
        highlight-current-row
        @current-change="handleCurrentChange"
        @selection-change="handleSelectionChange"
        @sort-change="sortChange"
        @row-click="rowClick"
        @row-dblclick="rowDbClick"
        :default-expand-all="true"
        :header-cell-class-name="handleHeaderClass"
        @header-click="handleHeaderCLick"
        
        style="width: 100%" v-if="showTable&&isMobile=='Y'">
          <el-table-column type="expand">
            <template slot-scope="props">
              <div style='width:100%;padding:10px'>
                   <div style='display:inline-block;float:left' v-for="(item,index2) in listFileMore" :key="index2">
                         <div style='width:70px;display:inline-block;'>{{item.names}}:</div>
                         <div style='width:120px;display:inline-block;'>{{ props.row[item.field] }}</div>
                        
                   </div>
              </div>
             
          </template>
        </el-table-column>
        
        <el-table-column
          :prop="item.field"
          :label="item.names"
          :sortable="item.sort ? 'custom':false"
          :width="item.width" v-for="(item,index) in listFieldNew " :key='index'>
          <template slot-scope="scope">
            <img :src="scope.row[item.field]" v-if="item.type=='image'"  style='height:60px'/>
            <span v-html="scope.row[item.field]" class="impleName" v-else></span>
          </template>
        </el-table-column>

        <el-table-column
          fixed="right"
          :prop="btnField.field"
          :label="btnField.names"
          :width="btnField.width" v-if="btnField" >
           <template slot-scope="scope">
             <div style='display:inline' v-for="(item,index) in scope.row[btnField.field]" :key="index">
                  <el-button plain type="success" size="mini" @click="btnClick(item)" v-if="!item.show||scope.row[item.show]=='Y'" style='margin-left:5px;margin-top:5px'>{{item.buttonName}}</el-button>
             </div>
            
            
          </template>
        </el-table-column>
        <div slot="empty">
          <p>
             <img src="../../assets/img/nodata.png"/>
          </p>
          <p>
            暂无数据
          </p>
        </div>

      </el-table>


      <div class='footer' v-if="!noPage">
        <el-pagination
          background
           layout="total, sizes, prev, pager, next, jumper"
           :page-size="30"
           :current-page="page"
            @size-change="handleSizeChange"
            @current-change="handleCurrentPageChange"
          :total="count">
        </el-pagination>
      </div>
      
  </div>
  
</template>

<script>
export default {
    props:['listField','selectType','url','tabJson','searchJson','sKey','listname','sKey2','noPage','company','defaultOrder','multiOrder','exId','appid','model_key','model','buttons','isReverse','isSearch','noclick'],
    name: "simple-table",
    data(){
        return {
            btnWidth:'110px',
            isMobile:"N",
            tableData:[],
            buttonCopy:[],
            currentRow:null,/**当前点击行 */
            multipleSelection:null,
            btnField:null,
            listFieldNew:[],/**新的字段json */
            listFileMore:[],
            showTable:false,
            count:1,/**总条数 */
            page:1,/**当前页数 */
            limit:30,/**每页多少条 */
            loading:true,
            isMonthDate:'N',
            searchMonth:'',
            activeThread:{},//保存所选择的表头
            ordersList:this.defaultOrder,
            sortColumn:{},
            defaultOrders:"",
            isTree:"",
            treeId:"",
            treeIdVal:"",
            parentId:"",
            treeData:[],
            treeIds:[],
            treeObjs:[],
            isDateTotal:false,
            isFirst:"Y",
            dateFields:[],
            dayIndex:-1,
            totalJson:{},
            totalxj:{},
            isXj:false,
            totalMsg:{},
            showSummary:false,
            isLoad:false,
            totalFields:"",//所有需要合计的列
            countJson:"",//目前给左边城市显示数字
        }
    },
   
    watch:{
      listField(val){
        let sef=this;
        sef.listFieldNew=[];
        if(this.listField.length>0){
            this.initList();
        }
        if(this.isMonthDate=='Y')
          this.loadData();
      },
      searchJson(val){
        console.log(val,"searchJson=s=s=s=s=s=s=")
         if(this.url){
            this.page=1;//查询后，页面重新定位到第1页
            this.loadData();
         }
      },
      tabJson(val){
        if(this.url){
          this.page=1;
          this.loadData();
        }
      }
    },
    created(){
       
        
      if(localStorage.getItem("ismobile")=="Y")
        this.isMobile="Y";
    },
    updated(){
      this.ordersList=[];
    },
    mounted(){
      let sef=this; 
      if(this.listField.length>0){
         this.initList();
      }

      for(let i=0;i<this.searchJson.length;i++){
         let searchId=this.searchJson[i].searchId;
         let vals=this.searchJson[i].vals;
         if(vals){
           this.searchJson[i].val=vals;
         }
      }
      //注释，因为会出现两次请求
     // alert(this.isSearch)
      if(this.url&&(this.isSearch!="N")){
        this.loadData();

      }
      window.setTimeout(function(){
        if(!sef.isLoad){
          sef.loadData()
          sef.isLoad=true;
        }
      },1000)
      this.isFirst="N"
    }, 
    activated(){
    },
    methods: {
      
      initList(){
          if(localStorage.getItem("ismobile")=="Y")
            this.isMobile="Y";
          
          let sef=this;
          sef.listFieldNew=[];
         
          if(this.listField.length>0){
              if(this.isMobile!="Y"){
                  this.dateFields=[];
                  for(let i=0;i<sef.listField.length;i++){
                    let item=sef.listField[i];
                    if(item.type=="total"||item.type=="totalNum"){//是否需要合计列
                       this.showSummary=true;
                       this.totalFields=this.totalFields=="" ? item.field:this.totalFields+","+item.field;
                       
                    }
                    try{
                      if(item.isxj=="Y"){
                        this.isXj=true;
                      }
                      if(item.totalMsg){
                        this.totalMsg[item.field]=item.totalMsg;
                      }
                    }catch(e){}
                    
                    if(item.names!='操作'&&item.field!="datenum"&&item.field!="createDateTotal"){
                        sef.listFieldNew.push(item);
                        this.dateFields.push(item.field);
                    }else if(item.field!="datenum"&&item.field!="createDateTotal"){
                        sef.btnField=item;
                    }
                    if(item.field=='datenum'){ //暂时无用
                      this.isMonthDate='Y';
                    }
                    if(item.field=="createDateTotal"){ //就是选择月份，然后列是1到31天那种表结构
                       this.dayIndex=this.listFieldNew.length;
                       this.isDateTotal=true;
                       let data=this.getSearchData();

                      // [{"searchType":"date2","field":"gcb_dat1","opr":">=","placeholder":"","text":"安葬日期","searchId":"startDate","vals":"2021-09-01"},{"searchType":"date2","field":"gcb_dat1","opr":"<=","placeholder":"","text":"至","searchId":"endDate","vals":"2021-09-30"}]

                       let startDate=data["startDate"];
                       let endDate=data["endDate"];

                       if(!startDate){
                          for(let h=0;h<this.searchJson.length;h++){
                            if(this.searchJson[h].searchId=="startDate"){
                              startDate=this.searchJson[h].vals;
                            }
                            if(this.searchJson[h].searchId=="endDate"){
                              endDate=this.searchJson[h].vals;
                            }
                          }
                       }
                       let searchGroupType=sessionStorage.getItem("searchGroupType");
                      
                       if(searchGroupType&&searchGroupType=="年"){
                        let years=startDate.substring(0,4);
                        for(let j=1;j<=12;j++){
                            let items={};
                            let day_=j;
                            if(j<10){
                              day_="0"+j;
                            }
                            items.field=years+"-"+day_;
                            items.names=""+day_;
                            items.width=item.width
                            this.listFieldNew.push(items);
                        }
                       }else{
                        let day=this.getDaysBetween(startDate,endDate);
                        let month=startDate.substring(0,7);
                        for(let j=1;j<=day+1;j++){
                            let items={};
                            let day_=j;
                            if(j<10){
                              day_="0"+j;
                            }
                            items.field=month+"-"+day_;
                            items.names=""+day_;
                            items.width=item.width
                            this.listFieldNew.push(items);
                        }
                      }
                       
                      let items={};
                      
                      items.field="合计";
                      items.names="合计";
                      items.width="100px"
                      this.listFieldNew.push(items);
                                                                                                                                                                                                                                                                                                                                              
                    }
                } 
              }else{
                let index=sef.listField.length>4 ? 4:sef.listField.length;
                for(let i=0;i<index;i++){
                    let item=sef.listField[i];
                    if(item.names!='操作'&&item.field!="datenum"){
                        sef.listFieldNew.push(item);
                    }else if(item.field!="datenum"){
                        sef.btnField=item;
                    }
                    if(item.field=='datenum'){
                      this.isMonthDate='Y';
                    }
                } 
                if(sef.listField.length>4){
                  for(let i=4;i<sef.listField.length;i++){
                     let item=sef.listField[i];
                     sef.listFileMore.push(item);
                  }
                }
              }
              

              if(this.buttons&&this.buttons.length>0){
                 
                 let fields={};
                 fields.names="操作";
                 fields.field="btn";
                 sef.btnField=fields;
              }
             
          }


      },
      initData(isTree,obj,noScroll){
          this.page=1;
          this.loadData(isTree,obj);
          if(!noScroll)
            this.$refs.table.bodyWrapper.scrollTop=0;
      },
      getSearchData(isTree){
          let data={};
          let dataEx={};
          console.log(this.searchJson,"searchJson===========")
          for(let i=0;i<this.searchJson.length;i++){
              let searchId=this.searchJson[i].searchId;
              let val=this.searchJson[i].val;
              data[searchId]=val;
              let _data={};
              _data.field=this.searchJson[i].field;
              _data.searchType=this.searchJson[i].searchType;
              
              _data.searchOper=this.searchJson[i].searchOper;

              if(!this.searchJson[i].searchOper&&this.searchJson[i].opr){
                _data.searchOper=this.searchJson[i].opr
              }
              dataEx[searchId]=_data;

          }
          for(let i=0;i<this.tabJson.length;i++){
              let searchId=this.tabJson[i].tabId;
              let curVal=this.tabJson[i].curVal;
              let isDateSelect=this.tabJson[i].isDateSelect;
              if("Y"==isDateSelect){
                let searchIds=searchId.split("#");
                data[searchIds[0]]=curVal[0];
                data[searchIds[1]]=curVal.length>1 ? curVal[1]:'';

                  let _data={};
                  _data.field=this.tabJson[i].tabField;
                  _data.searchType="date";
                  _data.searchOper=">="
                  dataEx[searchIds[0]]=_data;

                  let _data_={};
                  _data_.field=this.tabJson[i].tabField;
                  _data_.searchType="date";
                  _data_.searchOper="<="
                  dataEx[searchIds[1]]=_data_;
              }else if(searchId.split("#").length>1){
                  let searchIds=searchId.split("#");
                  data[searchIds[0]]=curVal;
                  data[searchIds[1]]=curVal;
                  
                  let _data={};
                  _data.field=this.tabJson[i].tabField;
                  _data.searchType="date";
                  _data.searchOper=">="
                  dataEx[searchIds[0]]=_data;

                  
                  let _data_={};
                  _data_.field=this.tabJson[i].tabField;
                  _data_.searchType="date";
                  _data_.searchOper="<="
                  dataEx[searchIds[1]]=_data_;
              }else{

                if(!data[searchId]){
                    data[searchId]=curVal;

                  let _data={};
                  _data.field=this.tabJson[i].tabField;
                  _data.searchType="tab";
                  if(this.tabJson[i].opr)
                    _data.opr=this.tabJson[i].opr;
                  else
                    _data.opr="";
                  dataEx[searchId]=_data;
                }
                
              }
              
          }
          if(isTree)
            data[this.parentId]=this.treeIdVal;
          let _data_={}
          _data_.field=this.parentId;
          _data_.searchType="hidden";
          dataEx[this.parentId]=_data_;

        // data['tabStr']=JSON.stringify(this.tabJson);
          data.page=""+this.page;
          data.limit=""+this.limit;
          data.sKey=this.sKey;
          data.sKey2=this.sKey2;
          if(this.exId)
            data.exId=this.exId;
          else 
            data.exId="";
          data.listname=escape(this.listname);
          data.key=this.model_key;
          data['dataEx']=JSON.stringify(dataEx);
          data['data']=JSON.stringify(data);
          data['company']=this.company;
          data['model']=this.model;
          if(this.ordersList){
              let order="";
              for(let i=0;i<this.ordersList.length;i++){
                  let orderColumn=this.ordersList[i].orderColumn;
                  let orderState=this.ordersList[i].orderState;
                  orderState=orderState=="descending" ? "desc":orderState;
                  orderState=orderState=="ascending" ? "asc":orderState;

                  if(orderState){
                    order=order=="" ? orderColumn+" "+orderState:order+","+orderColumn+" "+orderState;
                  }
              }
             // order=order.replace(/'/g,"''")
             if(order.indexOf("'")!=-1)
              order="";
              data["order"]=order;
          }
          return data;
      },
      loadData(isTree,obj){
        this.isLoad=true;
         let data=this.getSearchData(isTree);
       // console.log(data,"searchData===========")

         if(this.isMonthDate=='Y'){
            let isCreateMonthDate='N';
            let searchMonth=data.searchMonth;
            
            for(let i=0;i<this.listFieldNew.length;i++){
              if(this.listFieldNew[i].isDay=='Y'&&this.searchMonth==searchMonth)
                isCreateMonthDate='Y';
            }
           
            if(isCreateMonthDate!='Y'){
                let searchMonth=data.searchMonth;
                this.searchMonth=searchMonth;
                this.initList();
                this.$post(this.appid,"apiServe/getCommonDate",{searchMonth:searchMonth}).then(datas=>{
                  for(let i=0;i<datas.length;i++){
                    this.listFieldNew.push(datas[i])
                  }
                  this.loadDataChild(data,isTree,obj);
                })
            }else{
               this.loadDataChild(data,isTree,obj);
            }
            
         }else{
           this.loadDataChild(data,isTree,obj);
         }
      },
      initTableData(datas){
          let dateMap={};
          let dateMap2={};
          for(let i=0;i<datas.length;i++){
             let data=datas[i];
             let key="";
             for(let j=0;j<this.dateFields.length;j++){
               let val=data[this.dateFields[j]];
               key+=val;
             }
             let temp={};
             if(dateMap[key]){
               temp=dateMap[key];
             }else{
                for(let j=0;j<this.dateFields.length;j++){
                    temp[this.dateFields[j]]=data[this.dateFields[j]];
                }
             }
             let days=data["days"];
             let num=data["num"];
             temp[days]=num;
             dateMap[key]=temp;

             let temp2={};
             if(dateMap2["合计"]){
                 temp2=dateMap2["合计"]
             }else{
               temp2[this.dateFields[0]]="合计";
               for(let j=1;j<this.dateFields.length;j++){
                    temp2[this.dateFields[j]]="";
                }
             }
             let nums=0;
             if(temp2[days]){
               nums=temp2[days];
             }
             nums+=Number(num);
             temp2[days]=nums;
             dateMap2["合计"]=temp2;
          }
          let datas2=[];
          for(let col in dateMap){
             let temp=dateMap[col];
             let total=0;
             for(let j=this.dayIndex;j<this.listFieldNew.length;j++){
                let num=0;
                if(temp[this.listFieldNew[j].field]){
                  num=Number(temp[this.listFieldNew[j].field])
                }else{
                  temp[this.listFieldNew[j].field]="";
                }
                total+=num;
             }
             temp["合计"]=total;
            
             datas2.push(temp);
          }
          //最后一行合计
           for(let col in dateMap2){
             let temp=dateMap2[col];
             let total=0;
             for(let j=this.dayIndex;j<this.listFieldNew.length;j++){
                let num=0;
                if(temp[this.listFieldNew[j].field]){
                  num=Number(temp[this.listFieldNew[j].field])
                }else{
                  temp[this.listFieldNew[j].field]="";
                }
                total+=num;
             }
             temp["合计"]=total;
             datas2.push(temp);
          }
          return datas2;
      },
      loadDataChild(data,isTree,obj){
          if(this.isDateTotal){
             this.initList();
          }
          this.loading=true;
          let sef=this;
          let appid=this.appid;
          let url=this.url;
          if(url.indexOf("appid")!=-1){
             let index=url.indexOf("#");
             appid=url.substring(0,index);
             url=url.substring(index+1);
             appid=appid.replace("appid=","")
          }
          this.$post(appid,url,data).then(data=>{
              this.treeId=data.treeId;
              this.isTree=data.isTree;
              this.totalJson=data.total;
              this.totalxj=data.totalxj;
              this.parentId=data.parentId;
              this.showTable=true;
              this.defaultOrders=data.orderBy;
              try{
                this.countJson=data.countJson;
                this.$emit("countJson",JSON.stringify(this.countJson))
              }catch(e){}
              
              let datas=data.data;
              if(this.isDateTotal){
                sef.tableData=this.initTableData(data.data)
               
              }else{
                if(isTree){
                  sef.treeData=data.data
                  obj(sef.treeData);
                }else
                  sef.tableData=data.data;
              }
              try{
                if(this.totalxj&&this.isXj){
                  this.totalxj[this.listFieldNew[1].field]="小计"
                  for(let key in this.totalxj){
                    if(this.totalMsg[key]){
                      this.totalxj[key]=this.totalMsg[key].replace(key,this.totalxj[key])
                    }
                  }
                  sef.tableData.push(this.totalxj)
                }
              }catch(e){}
              
              /*if(this.isReverse=="Y"){
                  let listJson=[];
                  let rowField="names"
                  let colField="days"
                  let rows=[];
                  let col_={};
                  col_.field=colField;
                  col_.names="日期";
                  col_.width="100px";
                  listJson.push(col_)
                  //生成新列
                  for(let i=0;i<this.tableData.length;i++){
                     
                      for(let key in this.tableData[i]){
                        if(key==rowField){
                           let col={};
                           col.field=this.tableData[i][key];
                           col.names=this.tableData[i][key];
                           col.width="80px"
                           listJson.push(col);
                           
                        }

                      }
                  }
                  //先把列都转成行
                  for(let i=0;i<this.listFieldNew.length;i++){
                    let row={};
                    row[this.listFieldNew[i].field]=this.listFieldNew[i].names;
                    for(let j=0;j<this.listJson.length;j++){
                      row[this.listJson[j].field]="";
                    }
                    rows.push(row)
                  }
                  for(let i=0;i<this.tableData.length;i++){
                     let rowFieldVal=this.tableData[i][rowField]
                     let colFieldVal=this.tableData[i][colField]
                     
                  }
              
              }*/
              //添加行内按钮
              if(this.buttons&&this.buttons.length>0){
                  let maxSize=0;//计算最多的按钮个数
                  for(let i=0;i<sef.tableData.length;i++){
                    let row=sef.tableData[i];

                    
                    let buttons=[];
                    let sizes=0;
                    for(let j=0;j<this.buttons.length;j++){
                      let button=JSON.parse(JSON.stringify(this.buttons[j]));
                      
                      let condition=button.condition;
                      let isOk=true;
                      if(condition){
                        try{
                            condition=condition.replace(/''''/g,"\"");
                            condition=condition.replace(/'''/g,"\"");
                            condition=condition.replace(/''/g,"\"");
                           
                            condition=JSON.parse(condition);
                        }catch(e){}
                        
                        for(let h=0;h<condition.length;h++){

                          let con=condition[h];
                          
                          let field=con.field;
                          let opr=con.opr;
                          let val=con.val;
                          let val_=row[field];
                          console.log(JSON.stringify(row))
                      console.log("uisOk========"+field+"=="+opr+"=="+val+"=="+val_)
                          if(opr=="等于"&&val!=val_){
                            isOk=false;
                          }else if(opr=="不等于"&&val==val_){
                            isOk=false;
                          }
                        }
                      }

                      console.log("uisOk========"+isOk)
                      if(isOk){
                        let key=button.key;
                        let sId=row[key];
                        if(!sId)
                          sId="";
                        button.sId=sId;

                         if(button.exData){
                           let exData=button.exData
                           try{
                              exData=exData.replace(/''''/g,"\"");
                              exData=exData.replace(/'''/g,"\"");
                              exData=exData.replace(/''/g,"\"");
                              exData=JSON.parse(exData);
                           }catch(e){}
                           
                           for(let key_ in exData){
                             exData[key_]=row[exData[key_]];
                           }
                           button.exData=exData
                         }
                            

                        buttons.push(button);
                        sizes+=button.buttonName.length;
                      }
                    }
                    sizes+=4;
                    if(maxSize<sizes)
                       maxSize=sizes;
                    if(buttons.length>=5){
                        let buttons_=[];
                        sizes=0;
                        let child_=[];
                        for(let h=0;h<buttons.length;h++){
                            if(buttons[h].isMore=="Y"){
                              buttons[h].command=buttons[h].buttonName+"#"+buttons[h].sId;
                              child_.push(buttons[h]);

                            }else{
                              buttons_.push(buttons[h])
                              sizes+=buttons[h].buttonName.length;
                            }
                             
                        }
                       
                        let child={};
                        child.isChild="Y";
                        child.buttonName="更多";
                        child.child=child_;
                        buttons_.push(child);
                        buttons=buttons_;

                        sizes+=child.buttonName.length;
                        sizes+=4;
                        maxSize=sizes;
                    }
                    sef.tableData[i]["btn"]=buttons;
                  }
                  
                  this.btnWidth=maxSize*25;
              }
              sef.count=Number(data.count);
              sef.loading=false;

              this.$nextTick(() => {
                if(sef.tableData.length>0){
                
                    if(this.noclick!="Y"){
                      try{
                        sef.$refs.table.setCurrentRow(sef.tableData[0]);
                    
                        sef.$refs.table.toggleRowSelection(sef.tableData[0]);
                        sef.$emit("rowClick",JSON.stringify(sef.tableData[0]))
                      }catch(e){}
                      
                    }
                   
                  }else{
                    sef.$emit("empty","")
                  }
              })
             
             
              if(this.isMonthDate=='Y'){
                  let rows={};
                  rows.names="合计";

                  
                  for(let i=0;i<this.listFieldNew.length;i++){
                     if(this.listFieldNew[i].isDay=='Y'){
                       rows[this.listFieldNew[i].field]='';
                     }
                  }

                  
                  let dataNew=[];
                  for(let i=0;i<datas.length;i++){
                     let row_={};
                     let index=-1;
                     for(let j=0;j<dataNew.length;j++){
                       if(dataNew[j]['names']==datas[i]['names']){
                         row_=dataNew[j];
                         index=j;
                       }
                     }
                     row_["names"]=datas[i]['names'];
                     row_[datas[i]['days']]=datas[i]['num'];
                     if(index==-1){
                       row_['No']=dataNew.length+1;
                       dataNew.push(row_)
                    }else
                      dataNew[index]=row_;

                  }
                  datas=dataNew;
                  sef.tableData=dataNew;
                  let totals=0;
                  for(let i=0;i<datas.length;i++){
                    let total=0;
                    for(let j=0;j<this.listFieldNew.length;j++){
                        
                        if(this.listFieldNew[j].isDay=='Y'){
                           if(datas[i][this.listFieldNew[j].field])
                              total+=Number(datas[i][this.listFieldNew[j].field]);
                        }
                        sef.tableData[i]['row_total']=total;//计算每行的合计
                    }
                    totals+=total;//总合计
                    for(let i=0;i<this.listFieldNew.length;i++){
                         if(this.listFieldNew[i].isDay=='Y'){
                            let field=this.listFieldNew[i].field;
                            let total=0;
                            for(let j=0;j<datas.length;j++){
                              if(datas[j][field])
                                total+=Number(datas[j][field]);//计算每列的合计
                            }
                            total=total==0||total=="0" ? "":total;
                            rows[field]=total;
                         }
                    }
                  

                  }
                  rows['row_total']=totals;
                  sef.tableData.push(rows);
              }
              if(!isTree){
                for(let i=0;i<sef.treeIds.length;i++){
                    this.treeIdVal=sef.treeIds[i];
                    this.initData(true,sef.treeObjs[i]);
                }
              }
              

          });
      },
      load(tree, treeNode, resolve) {
          this.treeIdVal=tree[this.treeId];
          this.initData(true,resolve,true);
          this.treeIds.push(tree[this.treeId])
          this.treeObjs.push(resolve);
          
      },
      handleSizeChange(val) {
         this.limit=""+val;
          this.loadData()
         
      },
      handleCurrentChange(val) {
        
        this.currentRow=val;
        
      },
      handleCurrentPageChange(val){
         
        this.page=""+val;
        this.loadData()
        
      },
      setCurrent(row) {
        this.$refs.singleTable.setCurrentRow(row);
      },
     
      handleSelectionChange(val) {
        this.multipleSelection = val;
       
        this.$emit("rowMultiClick",JSON.stringify(val));
      },
      
      handelThreadStyle({row,column,rowIndex,columnIndex}){
          
          if(this.activeThread[column.property]){
            column.order=this.activeThread[column.property]
          }
      },
       filterHandler(value, row, column) {
            const property = column['property'];
            return row[property] === value;
      },
      rowClick(row, column, event){
          this.$emit("rowClick",JSON.stringify(row))
          this.$refs.table.clearSelection();
          this.$refs.table.toggleRowSelection(row);
      },
      rowDbClick(row, column, event){
          this.$emit("rowDbClick",JSON.stringify(row))
      },
      getScrollTop(){
       // console.log("scrollllletopllldsjfldsjfldsfjldsfjdsfdlksfjldsf");
          let scrollTop=this.$refs.table.bodyWrapper.scrollTop;
          //console.log("scrolltop==="+scrollTop)
          return scrollTop;
      },
      setScrollTop(top){
          this.$refs.table.bodyWrapper.scrollTop=top;
      },
      handleHeaderClass({ column }) {
         //if(!column.multiOrder){
           if(this.ordersList){
             let id=column.property;
              let order="";
              for(let i=0;i<this.ordersList.length;i++){
                if(id==this.ordersList[i].orderColumn){
                    order=this.ordersList[i].orderState;
                }
              }
            column.order=order;
            column.multiOrder=order;
           }
            
         /* }else{
            
            column.order = column.multiOrder
         }*/
        // console.log(column);
     
        
      },
      sortChange(obj,type){
        
        if(this.sortColumn[obj.column.property]){
          if(this.sortColumn[obj.column.property]=="ascending"){
            this.sortColumn[obj.column.property]="descending"
          }else{
            this.sortColumn[obj.column.property]="";
          }
        }else{
          this.sortColumn[obj.column.property]="ascending"
        }
        this.handleOrderChange(obj.column.property, this.sortColumn[obj.column.property])
       
      },
      // 点击表头
      handleHeaderCLick(column) {
         
         /* if (column.sortable !== 'custom') {
              return
          }
        
          if (column.multiOrder === 'descending') {
              column.multiOrder = 'ascending'
          } else {
              column.multiOrder = 'descending'
          }*/
         // this.handleOrderChange(column.property, column.multiOrder)
      },
      handleOrderChange (orderColumn, orderState) {
          let result = null;
          for(let i=0;i<this.ordersList.length;i++){
            if(this.ordersList[i].orderColumn==orderColumn){
              result=this.ordersList[i];
            }
          }
          if (result) {
              result.orderState = orderState
          } else {
              
              if(this.multiOrder!='Y'){
                  this.ordersList=[];
              }
              this.ordersList.push({
                  orderColumn: orderColumn,
                  orderState: orderState
              })
          }
          this.loadData();
          // 调接口查询，在传参的时候把ordersList进行处理成后端想要的格式
          //this.getDataList()
      },
      // 上面缺点是只能通过点击表头切换排序状态，点击小三角排序不会触发，处理sort-change事件和点击表头一样
      // 列表排序
      handleTableSort({ column }) {
          // 有些列不需要排序，提前返回
          if (column.sortable !== 'custom') {
              return
          }
          if (!column.multiOrder) {
              column.multiOrder = 'descending'
          } else if (column.multiOrder === 'descending') {
              column.multiOrder = 'ascending'
          } else {
              column.multiOrder = ''
          }
          this.handleOrderChange(column.property, column.multiOrder)
      },
      addComment:function (event) {
          let flagUrl=event.target.getAttribute("flagUrl");
          let flag=event.target.getAttribute("flag");
          if(flag=="search"){
             this.$emit("goSearch",flagUrl);
          }else  if(flagUrl){
              let item={};
              item.buttonName=event.target.innerHTML;
              item.url=flagUrl
              this.$emit("openWin",JSON.stringify(item));
          }
      },
      openWins(item,rows){//点击链接打开窗口
          let items=JSON.parse(JSON.stringify(item));
          let exdata=items.exdata;
          if(exdata){
            let filename2=exdata.filename2;
            let field=exdata.field;
            let opr=exdata.opr;
            let val=exdata.val;
            let val_=rows[field];
            if(opr=="等于"&&val_==val){
              items.filename2=filename2;
            }
            if(opr=="不等于"&&val_!=val){
              items.filename2=filename2;
            }
          }
          if(items.sId){
            let sId=items.sId;
            sId=rows[sId];
            items.sId=sId;
          }
         
          if(items.exId){
            let exId=items.exId;
            exId=rows[exId];
            items.exId=exId;
          }
          //主要给list使用，搜索条件
          if(items.searchs){
            let search_={}
            let searchs=items.searchs.split("|");
            for(let search in searchs){
              let searchss=search.split(":");
              search_[searchss[0]]=rows[searchss[1]];
            }
            items.searchs=search_;
          }
         if(!items.url){
          items.url="/commonEdit"
         }
         this.$emit("openWin",JSON.stringify(items));
      },
      getUrlBase64(imgUrl) {
        return new Promise((resolve) => {
          let canvas = document.createElement("canvas");
          let ctx = canvas.getContext("2d");
          let img = new Image(); //允许进行跨域
          img.crossOrigin = "Anonymous";
          img.src = imgUrl;
          img.onload = function() {
            canvas.height = img.height; //图片的高度
            canvas.width = img.width;//图片的宽度
            ctx.drawImage(img, 0, 0, img.width, img.height);
            let dataURL = canvas.toDataURL("image/png");
            canvas = null;
            resolve(dataURL);
          };
        });
      },
      handleCommand(command){
         let commands=command.split("#");
         let buttonName=commands[0];
         let sId=commands[1]
        
         let item=null;
         for(let i=0;i<this.buttons.length;i++){
          if(buttonName==this.buttons[i].buttonName){
            item=JSON.parse(JSON.stringify(this.buttons[i]));
          }
         }
         item.sId=sId;
         this.btnClick(item)
      },
      btnClick(item){
        //console.log(item,"items=======================ss===")
        if(item.isDownLoad=="Y"){
            const link = document.createElement("a"); //自己创建的a标签
            link.href = item.sId;
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
            window.URL.revokeObjectURL(item.sId);
        }else if(item.isDownLoadSimpleImage=="Y"){
          this.getUrlBase64(item.sId).then((base64) => {
            const link = document.createElement("a");
            link.href = base64;
            link.download = this.$route.query.source;
            link.click();
          });
        }else if(item.type=="openWin"){
              let data={};
              data.buttonName=item.name;
              data.url=item.url;
              this.$emit("openWin",JSON.stringify(data));
              
          }else if(item.type=="search"){
            
             this.$emit("goSearch",item.url);
          }else if((item.buttonName.indexOf("打印")!=-1&&item.isPrint!="N"&&item.isPrint!="A")||item.isPrint=='Y1'||item.isPrint=='Y'){
              
              let wb_msgs=item.wb_msg.split("#");
              
              let isPrint=wb_msgs.length>1 ? wb_msgs[1]:"N";
              let item_={};
              item_.buttonName="打印"+wb_msgs[0];
              item_.url="/commonPrint?printName="+wb_msgs[0]+"&appid="+item.appid+"&sCurItem="+item.sId+"&token="+sessionStorage.getItem("token")+"&isPrint="+isPrint;
              if(isPrint=="Y"||item.isDialog=='Y'){
                
                this.$emit("prints",JSON.stringify(item));
              }else{
                this.$emit("openWin",JSON.stringify(item_));
              }
              //this.$emit("openWin",JSON.stringify(item_));
              if(item.isSearch=="Y"){
                let that=this;
                window.setTimeout(function(){
                  that.$emit("goSearch",item.url);
                },3000)
                
              }         
          }else if(item.type=="printView"){
              let data={};
              data.buttonName=item.name.indexOf("打印")==-1 ? "打印"+item.name:item.name;
              data.url="/commonPrint?"+item.url+"&token="+sessionStorage.getItem("token");
              this.$emit("openWin",JSON.stringify(data));
          }else{
            if(!item.wb_msg){
              item.key=item.modelKey;
              item.filename2=item.filename;
              try{
                if(item.exData)
                  item.exData=JSON.parse(item.exData.replace(/''/g,"\""));
              }catch(e){}
              let url=item.url;
              if(url.indexOf("list")!=-1){
                 url=url.indexOf("?")==-1 ? url+"?exId="+item.sId:url+"&exId="+item.sId;
                 item.url=url;
              }
              this.$emit("openWin",JSON.stringify(item));
            }else{
               this.$confirm(item.wb_msg, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let params={ids:item.sId};
                    params.filename=item.filename;
                    
                    this.$post(item.appid,item.url,params).then(data=>{
                        if(data[0].status=="+OK"){
                            this.$message({
                                message: unescape(data[0].msg),
                                  type: 'success'
                                });
                            this.loadData();
                        }else{
                            this.$alert(unescape(data[0].msg), '错误提示', {
                                confirmButtonText: '确定',
                                callback: action => {}
                            });
                        }
                    });
                }).catch(() => {
                            
                });
            }
          }
      },
      bigNumberTransform(value) {
        if (typeof value == 'string') {
          value = Number(value);
        }
        let unit = '';
        let k = 10000;
        let sizes = ['', '万', '亿', '万亿'];
        let i;
        if (value < k) {
          value = value;
        } else {
          i = Math.floor(Math.log(value) / Math.log(k));
          value = ((value / Math.pow(k, i))).toFixed(4);
          unit = sizes[i];
        }
        console.log('value',value.toFixed(4))
        return value.toFixed(4) + unit;
      },
      getSummaries(param) {//合计列方法
        console.log(this.totalFields,this.listname+"=========================")
        console.log("getSummaries================================================")
        const { columns, data } = param;
      
        const sums = [];
        columns.forEach((column, index) => {
          if(index==0){
            return;
          }
          if (index === 1) {
            sums[index] = '总计';
            return;
          }
          if((","+this.totalFields+",").indexOf(","+column.property+",")==-1)
            return;
          if(this.totalJson[column.property]){
            if(this.totalMsg[column.property]){
              sums[index]=this.totalMsg[column.property].replace(column.property,this.totalJson[column.property]);
            }else
              sums[index]=this.totalJson[column.property]
          }
         /* const values = data.map(item => Number(item[column.property]));
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
            sums[index] += ' 元';
          } else {
            sums[index] = 'N/A';
          }*/
        });
        return sums;
      },
      getDaysBetween(dateString1,dateString2){
        var  startDate = Date.parse(dateString1);
        var  endDate = Date.parse(dateString2);
        var days=(endDate - startDate)/(1*24*60*60*1000);
        // alert(days);
        return  days;
      },
      expandChange(row,expanded){
        if(!expanded){
          let id=row[this.treeId];
          let index=-1;
          for(let i=0;i<this.treeIds.length;i++){
            if(this.treeIds[i]==id)
              index=i;
          }
          this.treeIds.splice(index,1);
          this.treeObjs.splice(index,1);
        }

      },
      callPhone(phoneNumber) {
       
        window.location.href = "tel://" + phoneNumber;
      },
    }
}
</script>
<style  scoped>
  .app{
    width:100%;
    height:100%;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;

    display: flex;
    flex-direction: column; 
  }
  .app >>> .el-table--border::after, .el-table--group::after{
    width:0;
    
  }
  .app >>> .el-table::before{
    height:0;
  }
  .app >>> .el-table th>.cell{
    padding-left:1px !important;
    padding-right:1px !important;
    text-align: center;
  }
  .el-table{
    flex:1;
    display: flex;
    flex-direction: column;
  }
  .el-table >>> .el-table__body-wrapper{
    flex:1 !important;
    height:100%  !important;
  }
  .footer{
    height:40px;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    padding-top:5px;
    text-align:right;
    padding-right:30px;
     /*background:#f9f9f9;*/
     background:#fff;
    /* border-top:1px solid #ddd;*/
  }
  .cell{
    font-weight:normal;
    font-family: 微软雅黑;
    color:#666;
  }
  .el-table thead{
    font-weight:normal;
    font-family: 微软雅黑;
    color:#666;
  }
  th{
    font-weight:normal;
  }
  .el-pagination{
    font-weight: normal;
  }
  .impleName{
    max-width: 100%; /*最大宽度为当前元素的100%*/
    display: inline-block;
    white-space: nowrap;/*保证文本内容不会自动换行，如果多余的内容会在水平方向撑破单元格*/     
    overflow: hidden; /*隐藏超出单元格的部分*/    
    text-overflow: ellipsis; /*将被隐藏的那部分用省略号代替*/}

  .app>>>.impleName{
    display:block;
  }
</style>
<style>

.el-table__header th{
   /* background:#eeeeee !important;
    border-bottom:1px solid #ddd;
    border-right:1px solid #ddd;*/
  }
/* 用来设置当前页面element全局table 选中某行时的背景色*/
.el-table__body tr.current-row>td{
  background-color: #d3e8fe !important;
  /* color: #f19944; */  /* 设置文字颜色，可以选择不设置 */
}
/* 用来设置当前页面element全局table 鼠标移入某行时的背景色*/
.el-table--enable-row-hover .el-table__body tr:hover>td {
  background-color: #d3e8fe;
  /* color: #f19944; */ /* 设置文字颜色，可以选择不设置 */
}
.btns{
  border:0;
  cursor: pointer;
  color:#f9f9f9;
  border-radius: 5px;

}
.btns:hover{
  background: #599152;
}
.el-table__footer-wrapper tbody td, .el-table__header-wrapper tbody td{
  background-color: #F5F7FA !important;
  color: #606266 !important;
}
.app>>>.el-table__header{
  text-align: center;
}
</style>
<style >
  .el-table--border, .el-table--group{
    border:0 !important;
    border-top:2px solid #418aea  !important;
  }
  .el-table td, .el-table th{
      padding:8px 0 !important;
  }
  .el-table--border td, .el-table--border th, .el-table__body-wrapper .el-table--border.is-scrolling-left~.el-table__fixed{
    /*border-right:0 !important;*/
  }
  .el-table .cell, .el-table--border td:first-child .cell, .el-table--border th:first-child .cell{
    padding-left:6px !important;

  }
  .el-table .cell{
    padding-right:0 !important;
    line-height:20px !important;
  }
  .el-table-column--selection .cell{
    padding-right: 2px  !important;
  }
</style>
